package com.zhongjian.technologycal.mall.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.activity.shoppingcart.bean.ProductListBean;
import com.zhongjian.technologycal.mall.base.BaseContacts;
import com.zhongjian.technologycal.mall.utils.UiUtils;
import com.zhongjian.technologycal.mall.view.ListViewForScrollView;

import java.util.List;

/**
 * Created by wei on 2018/1/21.
 */

public class ConfrmOedersAdapter extends BaseAdapter {
    private Context context;
    private List<ProductListBean> forList;
    private int cancelPosition;
    public ConfrmOedersAdapter(Context context, List<ProductListBean> forList) {
        this.context = context;
        this.forList = forList;
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public Object getItem(int position) {
        return forList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = UiUtils.inflate(R.layout.items_confirm_orders_list);
            holder.con_lv_goods = convertView.findViewById(R.id.con_lv_goods);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }



        final MyAdapter adapter = new MyAdapter(forList);
        holder.con_lv_goods.setAdapter(adapter);
        return convertView;

    }

    private class ViewHolder {
        ListViewForScrollView con_lv_goods;//商品列表
    }

    /**
     * listview条目
     */
    private class MyAdapter extends BaseAdapter {
        private List<ProductListBean> details;

        public MyAdapter(List<ProductListBean> details) {
            this.details = details;
        }

        @Override
        public int getCount() {
            return details.size();
        }

        @Override
        public Object getItem(int position) {
            return details.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewSonHolder sonHolder;
            if (convertView == null) {
                sonHolder = new ViewSonHolder();
                convertView = UiUtils.inflate(R.layout.item_item_order_goods);
                sonHolder.con_order_iv_heading_photo = (ImageView) convertView.findViewById(R.id.con_order_iv_heading_photo);
                sonHolder.con_payment_tv_product_name = (TextView) convertView.findViewById(R.id.con_payment_tv_product_name);
                sonHolder.con_payment_tv_product_price = (TextView) convertView.findViewById(R.id.con_payment_tv_product_price);
                sonHolder.con_payment_tv_product_count = (TextView) convertView.findViewById(R.id.con_payment_tv_product_count);
                sonHolder.con_payment_tv_product_sp = convertView.findViewById(R.id.con_payment_tv_product_sp);
                convertView.setTag(sonHolder);
            } else {
                sonHolder = (ViewSonHolder) convertView.getTag();
            }
            if (details.get(position).getProduct() != null) {
//                sonHolder.iv_goods_pic.setImageURI(Uri.parse(details.get(position).getPic1()));
            }
            sonHolder.con_payment_tv_product_name.setText(details.get(position).getProduct().getProductname());

            sonHolder.con_payment_tv_product_price.setText("¥" + details.get(position).getProductSpec().getPrice());
            sonHolder.con_payment_tv_product_count.setText("" + details.get(position).getProductnum());
            Picasso.get().load(BaseContacts.BASE_URL +
                    details.get(position).getProduct().getProductphotos().get(0).getPhoto())
                    .into(sonHolder.con_order_iv_heading_photo);
            sonHolder.con_payment_tv_product_sp.setText("规格: "+details.get(position).getProductSpec().getSpecname());

            return convertView;
        }
    }

    private class ViewSonHolder {
        ImageView con_order_iv_heading_photo;

        TextView con_payment_tv_product_name;

        TextView con_payment_tv_product_sp;

        TextView con_payment_tv_product_price;

        TextView con_payment_tv_product_count;

        TextView tv_money;//人民币符号
    }


}
